package com.chatRobot.localtionDemo;

import java.io.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 把回答的问题全部转到本地
 */
public class DataSavedLocally {

    public void saveQuestionAndAnswer(String question,String answer,File file) {
        try {
            //修改
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file,true));
            bufferedWriter.write("my:{ "+question+" }");
            bufferedWriter.newLine();
            bufferedWriter.newLine();
            bufferedWriter.write("robot:{ "+answer+" }");
            bufferedWriter.newLine();
            bufferedWriter.newLine();
            bufferedWriter.close();
        }catch (Exception r){
            System.out.println("写入失败");
            r.printStackTrace();
        }

    }

    public  File fhwj(){
        String Url = new File("").getAbsolutePath() + "\\src\\main\\resources\\";
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss");
        String formattedDate3 = now.format(formatter3);
        String wjname = Url + formattedDate3+"ai.txt";
        File file = new File(wjname);
        if(!file.exists()){
            try {
                file.createNewFile();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return file;
    }

}
